package br.com.andreikeda.utility.gestor.finance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

import br.com.andreikeda.utility.gestor.R;
import br.com.andreikeda.utility.gestor.finance.storage.database.model.Category;
import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by ikeda on 22/01/15.\n\n
 * Contact: <b>andreikeda87@gmail.com</b> or <b>andre.ikeda@99motos.com</b>
 */
public class CategoriesAdapter extends BaseAdapter {

    private Context context;
    private List<Category> categories;

    public CategoriesAdapter(Context context, List<Category> categories) {
        this.context = context;
        this.categories = categories;
    }

    @Override
    public int getCount() {
        return categories.size();
    }

    @Override
    public Category getItem(int position) {
        return categories.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_category, viewGroup, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }
        else
            holder = (ViewHolder) convertView.getTag();

        holder.outputCategory.setText(getItem(position).getName());
        return convertView;
    }

    class ViewHolder {
        @InjectView(R.id.output_category)
        TextView outputCategory;

        public ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }

}
